package com.wodsy.phoenix.datadao.shopc.dao.impl;

import com.wodsy.phoenix.datadao.base.BaseHibernateDao;
import com.wodsy.phoenix.datadao.shopc.dao.ShopAuditDao;
import com.wodsy.phoenix.dataobject.shopc.model.ShopAudit;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

@Repository("shopAuditDao")
public class ShopAuditDaoImpl extends BaseHibernateDao<ShopAudit, Integer> implements ShopAuditDao {
	@Autowired
	@Qualifier(value="shopc")
	@Override
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public Class<ShopAudit> getModelClass() {
		return ShopAudit.class;
	}
	
	@Override
	public void saveOrUpdate(ShopAudit audit) {
		Integer shopId = audit.getShopId();
		if(shopId != null && shopId > 0){
			ShopAudit old = get(shopId);
			if(old == null){
				save(audit);
			}else{
				merge(audit);
			}
		}
	}

}
